package leetcode3;
import java.util.*;
public class test7 {
    public int lengthOfLongestSubstring(String s) {
        Map<Character,Integer> map = new HashMap<>();
        int n = s.length();
        int ans = 0;
        int left  = 0;
        for(int right = 0;right < n;right++){
            char c = s.charAt(right);
            if(map.containsKey(c)){
                left = Math.max(left,map.get(c) + 1);
            }
            ans = Math.max(ans,right - left + 1);
            map.put(c,right);
        }
        return ans;
    }
}
